/**
 * 返回当月有几天
 * @param {*} date 传入一个date对象
 * @returns 
 */
export const getMonthDays = (date)=>{
  let year = date.getFullYear()
  let month  = date.getMonth()
  return new Date(year,month + 1,0).getDate();
}
/**
 * 获取当前月份的第一天是一周的 星期几
 * @param {*} date 
 */
export const getMonthFirstDay = (date)=>{
  let year = date.getFullYear()
  let month  = date.getMonth()
  return new Date(year,month,1).getDay()
}
/**
 * 补充月头前面的备份
 * @param {*} date 
 * @returns 
 */
export const getPrevMonthWeekDay = (date) =>{
  let year = date.getFullYear()
  let month  = date.getMonth()
  let first = getMonthFirstDay(date)
  // 得到上个月最后一天
  const prevMonthDate = new Date(year, month,0)
  const prevMonthLastDay = prevMonthDate.getDate();
  const prevMonth = prevMonthDate.getMonth()
  const prevYear = prevMonthDate.getFullYear()
  let newArr = []
  for(let i = 0;i<first;i++){
    let dayObj = {
      year: prevYear,
      month: prevMonth,
      day: prevMonthLastDay - i,
    };
    newArr.unshift(dayObj)
  }
  return newArr
}
export const getNextMonthWeekDay = (date)=>{
  // 获取这个月的最后一天
  let monthLastDay = getMonthDays(date)
  let year = date.getFullYear()
  let month  = date.getMonth()
  // 获取最后一天是周几
  let lastDay = new Date(year,month,monthLastDay).getDay()
  let nextMonth = month === 11 ? 0 : month + 1
  let nextYear = month === 11 ? year + 1 : year
  let newArr = []
  for(let i = 1;i<=(6-lastDay);i++){
    let dayObj = {
      year: nextYear,
      month: nextMonth,
      day: i,
    };
    newArr.push(dayObj)
  }
  return newArr
}